| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | Mivhak.component('tab-pane', { |
||
| 62 | setEditor: function() { |
||
| 63 | |||
| 64 | // Remove redundant space from code |
||
| 65 | this.resource.pre.textContent = this.resource.pre.textContent.trim(); |
||
| 66 | |||
| 67 | // Set editor options |
||
| 68 | this.editor = ace.edit(this.resource.pre); |
||
| 69 | this.editor.setReadOnly(!this.mivhakInstance.options.editable); |
||
| 70 | this.editor.setTheme("ace/theme/"+this.getTheme()); |
||
| 71 | this.editor.setShowPrintMargin(false); |
||
| 72 | this.editor.renderer.setShowGutter(this.mivhakInstance.options.lineNumbers); |
||
| 73 | this.editor.getSession().setMode("ace/mode/"+this.resource.lang); |
||
| 74 | this.editor.getSession().setUseWorker(false); // Disable syntax checking |
||
| 75 | this.editor.getSession().setUseWrapMode(true); // Set initial line wrapping |
||
| 76 | |||
| 77 | this.editor.setOptions({ |
||
| 78 | maxLines: Infinity, |
||
| 79 | firstLineNumber: this.resource.startLine, |
||
| 80 | highlightActiveLine: false, |
||
| 81 | fontSize: parseInt(14) |
||
| 82 | }); |
||
| 83 | |||
| 84 | // Update source content for the live preview |
||
| 85 | if(this.mivhakInstance.options.editable) |
||
| 86 | { |
||
| 87 | this.editor.getSession().on('change', (function() { |
||
| 88 | this.mivhakInstance.resources.update(this.index, this.editor.getValue()); |
||
| 89 | }).bind(this)); |
||
| 90 | } |
||
| 91 | |||
| 92 | // Move view to show cursor position when the cursor moves |
||
| 93 | this.editor.session.selection.on("changeCursor", (function(e){ |
||
| 94 | e.preventDefault(); |
||
| 95 | raf((function(){ |
||
| 96 | var cursor = this.$el.find('.ace_cursor')[0].getBoundingClientRect(), |
||
| 97 | viewport = this.$el.find('.mivhak-tab-pane-inner')[0].getBoundingClientRect(), |
||
| 98 | up = viewport.top - cursor.top, |
||
| 99 | down = cursor.top + cursor.height - viewport.top - viewport.height, |
||
| 100 | left = parseInt(this.$el.find('.ace_content').css('margin-left').replace('px','')); |
||
| 101 | |||
| 102 | // Move the scrollbar vertically only if the cursor leaves the viewport |
||
| 103 | this.vscroll.doScroll('up',Math.max(0, up)); // |
||
| 104 | this.vscroll.doScroll('down',Math.max(0, down)); |
||
| 105 | this.vscroll.moveBar(); |
||
| 106 | |||
| 107 | // Ace Editor automatically moves the viewport, so we just need to move the scrollbar accordingly |
||
| 108 | this.hscroll.state.l = -left; |
||
| 109 | this.hscroll.moveBar(); |
||
| 110 | }).bind(this)); |
||
| 111 | }).bind(this)); |
||
| 112 | }, |
||
| 113 | markLines: function() |
||
| 130 | }); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.